home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 4 / ETO Development Tools 4.iso / Essentials / MacApp Documentation / MacApp.TECH$ Archives / 1990 / Jan 90 / MacApp.Tech$ 1⁄26⁄90 / 0526-Re dynamic menus-Jan90 < prev    next >
Encoding:
Text File  |  1991-03-06  |  2.4 KB  |  85 lines  |  [TEXT/GEOL]

  1. Item    1762206                         24-Jan-90        15:43
  2.  
  3. From:   AUST0134                        Jam Software Sydney,IVR
  4.  
  5. To:     DAWSON.M                        Dawson, Mark
  6.         MACAPP.TECH$                    MacApp Technical
  7.  
  8. Sub:    Re dynamic menus
  9.  
  10. Mark,
  11.  
  12. >What I'm not sure about is how to build a menu, informing MacApp that there's
  13. >a new item and what its command number is (so MacApp will fill in the
  14. >'itsChoice' field of my DoChoice() method with a number that I know how to
  15. >deal with).
  16.  
  17. You are confusing the DoChoice chain with the Command chain.  The DoChoice
  18. chain is traversed on clicking in a control.  The command chain is traversed
  19. when a menu item is selected or on a keystroke.
  20.  
  21. When MacApp handles a menu command which does not have an associated command
  22. number defined, (as in a menu with a dynamic number of items) it will return a
  23. negative command number. Your DoMenuCommand can convert this number to a menu
  24. and item number using CmdToMenuItem, and handle it appropriately.
  25. MacApp does not need to be informed specifically if you add or remove items,
  26. just ensure that your DoSetupMenus and DoMenuCommand can handle all the items
  27. you have on the menu.
  28.  
  29. {An example of using dynamic menus}
  30. PROCEDURE TMyView.RebuildMenus; OVERRIDE;
  31. VAR
  32.    count,i:INTEGER;
  33.    aStr:   Str255;
  34.    myMenu: MenuHandle;
  35. BEGIN
  36.    myMenu := GetMHandle( kMyMenuID );
  37.    count := CountMItems( myMenu );
  38.    FOR i := count DOWNTO 1 DO
  39.    DelMenuItem( myMenu, i );
  40.    EnableItem( myMenu, 0 );
  41. { rebuild the dynamic menu from my own list }
  42.    FOR i := 1 TO fFiles.fSize DO BEGIN
  43.    aStr := TNameObject(fFiles.At(i)).fName;
  44.    AppendMenu( myMenu, aStr );
  45.    END;
  46. END;
  47.  
  48. PROCEDURE TMyView.DoSetupMenus; OVERRIDE;
  49. VAR
  50.    count,i:INTEGER;
  51.    aStr:   Str255;
  52.    myMenu: MenuHandle;
  53. BEGIN
  54.    INHERITED DoSetupMenus;
  55. { we will enable all the items on the dynamic menu }
  56.    myMenu := GetMHandle( kMyMenuID );
  57.    count := CountMItems( myMenu );
  58.    FOR i := 1 TO count DO BEGIN
  59.     EnableItem( fileMenu, i );
  60.    END;
  61. END;
  62.  
  63. FUNCTION   TMyView.DoMenuCommand(aCmdNumber: CmdNumber):   TCommand; OVERRIDE;
  64. VAR
  65.    menu, item: INTEGER;
  66. BEGIN
  67.    DoMenuCommand := gNoChanges;
  68.    CmdToMenuItem(aCmdNumber, menu, item);
  69.    IF menu = kMyMenuID THEN BEGIN
  70.     CASE item OF
  71.         …
  72.             {Do your thing}
  73.         …
  74.     END;
  75.    END ELSE
  76.    DoMenuCommand := INHERITED DoMenuCommand(aCmdNumber);
  77. END;
  78.  
  79. With luck this will be of assistance.
  80.  
  81. Tseung Cheung
  82. JAM Software Pty Ltd
  83. AUST0134
  84.  
  85.